import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { DataService } from '../../services/data';
import Avatars from '@dicebear/avatars';
import SpriteCollection from '@dicebear/avatars-identicon-sprites';
import {DomSanitizer} from '@angular/platform-browser'

/**
 * Generated class for the AllCommentsPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-all-comments',
  templateUrl: 'all-comments.html',
  providers: [DataService]
})
export class AllCommentsPage {

  avatars = new Avatars(SpriteCollection);
  comments:any

  constructor(public navCtrl: NavController, public navParams: NavParams, public dataService: DataService,private sanitizer: DomSanitizer) {

  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad AllCommentsPage');

    this.dataService.getComments(this.navParams.get('game_id'), 50).subscribe((data) => {
      for(let item of data){
        item.icon = this.sanitizer.bypassSecurityTrustHtml(this.getIcon(item.user_id))
      }
      this.comments = data;
    })
  }

  getIcon(user_id){
    let svg = this.avatars.create(user_id);
    return svg;
  }

}
